<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>【数位DP】 洛谷 P2602 [ZJOI2010]数字计数 P2657 [SCOI2009] windy 数.md | 蓝湖畔淅淅沥沥的雨</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="说明 - 2022-05-05 本篇博客为本人原创, 原发布于CSDN, 在搭建个人博客后使用爬虫批量爬取并挂到个人博客, 出于一些技术原因博客未能完全还原到初始版本(而且我懒得修改), 在观看体验上会有一些瑕疵 ,若有需求会发布重制版总结性新博客。发布时间统一定为1111年11月11日。钦此。  洛谷 P2602 [ZJOI2010]数字计数 ​ #include  #include  #in">
<meta property="og:type" content="article">
<meta property="og:title" content="【数位DP】 洛谷 P2602 [ZJOI2010]数字计数 P2657 [SCOI2009] windy 数.md">
<meta property="og:url" content="http://example.com/1111/11/11/%E3%80%90%E6%95%B0%E4%BD%8DDP%E3%80%91%20%E6%B4%9B%E8%B0%B7%20P2602%20[ZJOI2010]%E6%95%B0%E5%AD%97%E8%AE%A1%E6%95%B0%20P2657%20[SCOI2009]%20windy%20%E6%95%B0/index.html">
<meta property="og:site_name" content="蓝湖畔淅淅沥沥的雨">
<meta property="og:description" content="说明 - 2022-05-05 本篇博客为本人原创, 原发布于CSDN, 在搭建个人博客后使用爬虫批量爬取并挂到个人博客, 出于一些技术原因博客未能完全还原到初始版本(而且我懒得修改), 在观看体验上会有一些瑕疵 ,若有需求会发布重制版总结性新博客。发布时间统一定为1111年11月11日。钦此。  洛谷 P2602 [ZJOI2010]数字计数 ​ #include  #include  #in">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="1111-11-11T03:06:11.000Z">
<meta property="article:modified_time" content="2022-05-06T07:27:38.941Z">
<meta property="article:author" content="StarsWhisper">
<meta property="article:tag" content="OldBlog(Before20220505)">
<meta property="article:tag" content="DP">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="蓝湖畔淅淅沥沥的雨" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/plugin/bganimation/bg.css">

  

  <link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" rel="stylesheet" type="text/css">
<meta name="generator" content="Hexo 6.1.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <div class="outer">
        <div class="widget-wrap mobile-header">
  <h3 class="widget-title"></h3>
  <div class="widget">
    <img class="avatar" src="/images/avatar.png">
    <h2 class="author">StarsWhisper</h2>
    <h3 class="description"></h3>
    <div class="count-box">
      <a href="/archives"><div><strong>75</strong><br>文章</div></a>
      <a href="/categories"><div><strong>31</strong><br>分类</div></a>
      <a href="/tags"><div><strong>56</strong><br>标签</div></a>
    </div>
    <ul class="blog-link">
     
          <a href="/" title="Home">
            <li>主页</li>
          </a>
        
          <a href="/archives" title="Archives">
            <li>归档</li>
          </a>
        
          <a href="/categories" title="Categories">
            <li>分类</li>
          </a>
        
          <a href="/tags" title="Tags">
            <li>标签</li>
          </a>
        
          <a href="/knightabout" title="Knightabout">
            <li>关于</li>
          </a>
        
          <a href="/bridges" title="Bridges">
            <li>传送门</li>
          </a>
        
          <a href="/announcement" title="Announcement">
            <li>公告</li>
          </a>
        
    </ul>
  </div>
</div>

        <section id="main"><article id="post-【数位DP】 洛谷 P2602 [ZJOI2010]数字计数 P2657 [SCOI2009] windy 数" class="wow slideInRight article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/1111/11/11/%E3%80%90%E6%95%B0%E4%BD%8DDP%E3%80%91%20%E6%B4%9B%E8%B0%B7%20P2602%20%5BZJOI2010%5D%E6%95%B0%E5%AD%97%E8%AE%A1%E6%95%B0%20P2657%20%5BSCOI2009%5D%20windy%20%E6%95%B0/" class="article-date">
  <time class="post-time" datetime="1111-11-11T03:06:11.000Z" itemprop="datePublished">
    <span class="post-month">11月</span><br/>
    <span class="post-day">11</span>
  </time>
</a>
   
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      【数位DP】 洛谷 P2602 [ZJOI2010]数字计数 P2657 [SCOI2009] windy 数.md
    </h1>
  

        <div>
          
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E7%AE%97%E6%B3%95/">算法</a>,<a class="article-category-link" href="/categories/%E7%AE%97%E6%B3%95/DP/">DP</a>
  </div>

          
              

          
        </div>
      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="说明-2022-05-05"><a class="markdownIt-Anchor" href="#说明-2022-05-05"></a> 说明 - 2022-05-05</h2>
<p>本篇博客为本人原创, 原发布于CSDN, 在搭建个人博客后使用爬虫批量爬取并挂到个人博客, 出于一些技术原因博客未能完全还原到初始版本(而且我懒得修改), 在观看体验上会有一些瑕疵 ,若有需求会发布重制版总结性新博客。发布时间统一定为1111年11月11日。钦此。</p>
<h2 id="洛谷-p2602-zjoi2010数字计数"><a class="markdownIt-Anchor" href="#洛谷-p2602-zjoi2010数字计数"></a> 洛谷 P2602 [ZJOI2010]数字计数</h2>
<p>​<br />
#include <iostream><br />
#include <cstdio><br />
#include <cstdlib><br />
#include <cstring><br />
#include <cmath><br />
#include <algorithm><br />
#include <string><br />
#include <queue><br />
#include <vector><br />
#include <stack><br />
#include <map><br />
#include <set><br />
typedef long long int LL;<br />
const int INF = 0x7fffffff, SCF = 0x3fffffff;<br />
const int N = 14, M = 1e4+5, K = 1e6+4, T = 10;<br />
LL dp[N][T][T];<br />
int dig[N];<br />
LL a,b;<br />
LL Qmul(int p)<br />
{<br />
LL base = 10, re = 1;<br />
while§{<br />
if(p&amp;1) re *= base;<br />
base *= base;<br />
p &gt;&gt;= 1;<br />
}<br />
return re;<br />
}<br />
LL fun(LL x,int num)<br />
{<br />
LL ans = 0;<br />
int len = 0;<br />
while(x){<br />
dig[<ins>len] = x%10;<br />
x /= 10;<br />
}<br />
for(int i=1; i&lt;len; i</ins>){<br />
for(int j=1; j&lt;T; j++){<br />
ans += dp[i][j][num];<br />
}<br />
}<br />
for(int i=1; i&lt;dig[len]; i++){<br />
ans += dp[len][i][num];<br />
}<br />
for(int i=1; i&lt;len; i++){<br />
for(int j=0; j&lt;dig[i]; j++){<br />
ans += dp[i][j][num];<br />
}<br />
for(int j=i+1; j&lt;=len; j++){<br />
if(dig[j] == num) ans += dig[i]*Qmul(i-1);<br />
//要算上前面的数<br />
}<br />
}<br />
return ans;<br />
}<br />
int main()<br />
{<br />
scanf(&quot;%lld%lld&quot;,&amp;a,&amp;b);<br />
for(int i=0; i&lt;T; i++) dp[1][i][i] = 1;<br />
for(int i=2; i&lt;=13; i++){<br />
for(int j=0; j&lt;T; j++){<br />
for(int k=0; k&lt;T; k++){<br />
for(int r=0; r&lt;T; r++){<br />
dp[i][j][r] += dp[i-1][k][r];<br />
}<br />
}<br />
dp[i][j][j] += Qmul(i-1);<br />
}<br />
}<br />
for(int i=0; i&lt;T; i++) printf(&quot;%lld &quot;,fun(b+1,i)-fun(a,i));<br />
return 0;<br />
}</p>
<h2 id="洛谷-p2657-scoi2009-windy-数"><a class="markdownIt-Anchor" href="#洛谷-p2657-scoi2009-windy-数"></a> 洛谷 P2657 [SCOI2009] windy 数</h2>
<p>抄完数字计数之后照葫芦画瓢做的这道题，遂去看了题解。<br />
离AC只差一句题解上抄来的 if(std::abs(dig[i+1]-dig[i]) &lt;= 1)<br />
break;，因为函数的参数可能就是一个非windy数，你需要找出这个比这个非windy数小的所有的的windy数，当if(std::abs(dig[i+1]-dig[i])<br />
&lt;= 1) break;这个条件满足时，之后找到的就必然时非windy数了，自然不需要继续找。<br />
<s>之前我自己的类似的判断思路错了，写题解的人yyds</s></p>
<p>​<br />
#include <iostream><br />
#include <cstdio><br />
#include <cstdlib><br />
#include <cstring><br />
#include <cmath><br />
#include <algorithm><br />
#include <string><br />
#include <queue><br />
#include <vector><br />
#include <stack><br />
#include <map><br />
#include <set><br />
typedef long long int LL;<br />
const int INF = 0x7fffffff, SCF = 0x3fffffff;<br />
const int N = 12, M = 1e4+5, T = 10;<br />
LL dp[N][N];<br />
int dig[N];<br />
int a,b;<br />
void build()<br />
{<br />
for(int i=0; i&lt;T; i++) dp[1][i] = 1;<br />
for(int i=2; i&lt;=T; i++) {<br />
for(int j=0; j&lt;T; j++){<br />
for(int k=0; k&lt;T; k++){<br />
if(std::abs(j-k) &lt;= 1) continue;<br />
dp[i][j] += dp[i-1][k];<br />
}<br />
}<br />
}<br />
}<br />
LL fun(int x)<br />
{<br />
LL ans = 0;<br />
int len = 0;<br />
while(x){<br />
dig[<ins>len] = x%10;<br />
x /= 10;<br />
}<br />
for(int i=1; i&lt;len; i</ins>){<br />
for(int j=1; j&lt;T; j++){<br />
ans += dp[i][j];<br />
}<br />
}<br />
//std::cout &lt;&lt; &quot; pre: &quot; &lt;&lt; ans;<br />
for(int j=1; j&lt;dig[len]; j++){<br />
ans += dp[len][j];<br />
}<br />
//std::cout &lt;&lt; &quot; now:&quot; &lt;&lt; ans;<br />
//if(len &gt;=2 &amp;&amp; std::abs(dig[len]-dig[len-1]) &lt;= 1) return ans;<br />
for(int i=len-1; i&gt;=1; i–){<br />
for(int j=0; j&lt;dig[i]; j++){<br />
if(std::abs(j-dig[i+1]) &lt;= 1) continue;<br />
ans += dp[i][j];<br />
}<br />
if(std::abs(dig[i+1]-dig[i]) &lt;= 1) break;<br />
}<br />
//std::cout &lt;&lt; &quot; post:&quot; &lt;&lt; ans &lt;&lt; &quot; “;<br />
return ans;<br />
}<br />
int main()<br />
{<br />
scanf(”%d%d&quot;,&amp;a,&amp;b);<br />
build();<br />
/*<br />
for(int i=1; i&lt;141; i++){<br />
std::cout &lt;&lt; “fun(” &lt;&lt; i &lt;&lt; “): &quot; &lt;&lt; fun(i+1) &lt;&lt; std::endl;<br />
}<br />
*/<br />
printf(”%lld&quot;,fun(b+1)-fun(a));<br />
return 0;<br />
}</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/1111/11/11/%E3%80%90%E6%95%B0%E4%BD%8DDP%E3%80%91%20%E6%B4%9B%E8%B0%B7%20P2602%20[ZJOI2010]%E6%95%B0%E5%AD%97%E8%AE%A1%E6%95%B0%20P2657%20[SCOI2009]%20windy%20%E6%95%B0/" data-id="cl2uhoecr002qe4j3bjt9con4" class="article-share-link">分享</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/DP/" rel="tag">DP</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/OldBlog-Before20220505/" rel="tag">OldBlog(Before20220505)</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/1111/11/11/%E3%80%90%E6%88%90%E9%95%BF%E8%AE%B0%E5%BD%95%E3%80%91%E3%80%90C%E8%AF%AD%E8%A8%80%E3%80%91%E5%B0%9D%E8%AF%95%E7%94%A8C%E8%AF%AD%E8%A8%80%E5%AE%9E%E7%8E%B0%E7%AE%80%E6%98%93%E8%B4%AA%E5%90%83%E8%9B%87/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">
        
          【成长记录】【C语言】尝试用C语言实现简易贪吃蛇.md
        
      </div>
    </a>
  
  
    <a href="/1111/11/11/%E3%80%90%E6%8D%A2%E6%A0%B9DP%E3%80%91Tree%20and%20Permutation/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">【换根DP】Tree and Permutation.md</div>
    </a>
  
</nav>

  
</article>



</section>
        
          <aside id="sidebar">
  
    <div class="widget-wrap">
  <h3 class="widget-title"></h3>
  <div class="widget">
    <h1 class="blog-title">蓝湖畔淅淅沥沥的雨</h1>
    <h2 class="blog-subtitle">All tragedy erased, I see only wonders...</h2>
    <ul class="blog-link">
     
          <a href="/" title="Home">
            <li>主页</li>
          </a>
        
          <a href="/archives" title="Archives">
            <li>归档</li>
          </a>
        
          <a href="/categories" title="Categories">
            <li>分类</li>
          </a>
        
          <a href="/tags" title="Tags">
            <li>标签</li>
          </a>
        
          <a href="/knightabout" title="Knightabout">
            <li>关于</li>
          </a>
        
          <a href="/bridges" title="Bridges">
            <li>传送门</li>
          </a>
        
          <a href="/announcement" title="Announcement">
            <li>公告</li>
          </a>
        
    </ul>
  </div>
</div>

  
    <div class="widget-wrap">
  <h3 class="widget-title"></h3>
  <div class="widget">
    <img class="avatar" src="/images/avatar.png">
    <h2 class="author">StarsWhisper</h2>
    <h3 class="description"></h3>
    <div class="count-box">
      <a href="/archives"><div><strong>75</strong><br>文章</div></a>
      <a href="/categories"><div><strong>31</strong><br>分类</div></a>
      <a href="/tags"><div><strong>56</strong><br>标签</div></a>
    </div>



    <div class="social-link">
      
        <a class="hvr-bounce-in" href="https://github.com/Wldcmzy" target="_blank" title="Github">
          Github
        </a>
      
        <a class="hvr-bounce-in" href="https://blog.csdn.net/wldcmzy" target="_blank" title="CSDN">
          CSDN
        </a>
      
        <a class="hvr-bounce-in" href="https://space.bilibili.com/83743701" target="_blank" title="bilibili(无技术和学习内容)">
          bilibili(无技术和学习内容)
        </a>
      
    </div>

    <div class="friend-link">
      <h2>友情链接</h2>
      
        <a class="hvr-bounce-in" href="https://shanamaid.github.io/" target="_blank" title="夏娜主题作者的博客">
          夏娜主题作者的博客
        </a>
      
    </div>
  </div>
</div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy;2021 - 2022 StarsWhisper<br>
      由<a href="http://hexo.io/" target="_blank">Hexo</a>强力驱动 | 
      主题-<a target="_blank" rel="noopener" href="https://github.com/ShanaMaid/hexo-theme-shana">Shana</a>(但是魔改)
      
    </div>
    
  </div>
</footer>
    </div>
    

<script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/wow/0.1.6/wow.min.js"></script>
<script>
new WOW().init();
</script>   


  
<link rel="stylesheet" href="/plugin/fancybox/jquery.fancybox.css">

  
<script src="/plugin/fancybox/jquery.fancybox.pack.js"></script>




  
<link rel="stylesheet" href="/plugin/galmenu/GalMenu.css">

  
<script src="/plugin/galmenu/GalMenu.js"></script>

  <div class="GalMenu GalDropDown">
      <div class="circle" id="gal">
        <div class="ring">
          
            <a href="/announcement" title="" class="menuItem">公告</a>
          
            <a href="/tags" title="" class="menuItem">标签</a>
          
            <a href="/categories" title="" class="menuItem">分类</a>
          
            <a href="/archives" title="" class="menuItem">归档</a>
          
            <a href="/knightabout" title="" class="menuItem">关于</a>
          
            <a href="/bridges" title="" class="menuItem">传送门</a>
          
        </div>
        
          <audio id="audio" src="#"></audio>
        
      </div> 
</div>
<div id="overlay" style="opacity: 1; cursor: pointer;"></div>
  <script type="text/javascript">var items = document.querySelectorAll('.menuItem');
    for (var i = 0,
    l = items.length; i < l; i++) {
      items[i].style.left = (50 - 35 * Math.cos( - 0.5 * Math.PI - 2 * (1 / l) * i * Math.PI)).toFixed(4) + "%";
      items[i].style.top = (50 + 35 * Math.sin( - 0.5 * Math.PI - 2 * (1 / l) * i * Math.PI)).toFixed(4) + "%"
    }</script>
<script type="text/javascript">
  $(document).ready(function() {
    $('body').GalMenu({
      'menu': 'GalDropDown'
    })
  });
</script>

  <section class="hidden-xs"> 
  <ul class="cb-slideshow"> 
    <li><span>苟利</span></li> 
    <li><span>国家</span></li> 
    <li><span>生死以</span></li> 
    <li><span>岂能</span></li> 
    <li><span>祸福</span></li> 
    <li><span>趋避之</span></li> 
  </ul>
</section>

<script src="/js/script.js"></script>




  </div>
</body>
</html>